import uuid from "uuid-js";
import axios from "axios"

export default {
    namespaced: true,
    actions: {
        addRandom(context) {
            axios.get("https://v1.jinrishici.com/rensheng.txt").then(
                (response) => {
                    context.commit("ADD_PERSON", response.data)
                },
                error => {
                    alert(error.message)
                })
        }
    },
//准备mutations对象---修改state中的数据
    mutations: {
        ADD_PERSON(state, value) {
            const person = {
                id: uuid.create().hex,
                name: value,
            }
            state.personList.push(person)
        }
    },
//准备state对象---保存具体的数据
    state: {
        personList: [
            {id: '001', name: '张三'},
        ]
    },
//准备getters对象---将state中的数据进行加工
    getters: {
        currentSize(state) {
            return state.personList.length
        }
    }
}